package com.znh.kuiklyuniversity.compose.widgets

import androidx.compose.runtime.Composable
import com.tencent.kuikly.compose.foundation.Image
import com.tencent.kuikly.compose.foundation.background
import com.tencent.kuikly.compose.foundation.layout.Arrangement
import com.tencent.kuikly.compose.foundation.layout.Column
import com.tencent.kuikly.compose.foundation.layout.PaddingValues
import com.tencent.kuikly.compose.foundation.layout.Row
import com.tencent.kuikly.compose.foundation.layout.aspectRatio
import com.tencent.kuikly.compose.foundation.layout.fillMaxHeight
import com.tencent.kuikly.compose.foundation.layout.fillMaxWidth
import com.tencent.kuikly.compose.foundation.layout.height
import com.tencent.kuikly.compose.foundation.layout.padding
import com.tencent.kuikly.compose.foundation.lazy.grid.GridCells
import com.tencent.kuikly.compose.foundation.lazy.grid.LazyHorizontalGrid
import com.tencent.kuikly.compose.foundation.lazy.grid.LazyVerticalGrid
import com.tencent.kuikly.compose.foundation.shape.RoundedCornerShape
import com.tencent.kuikly.compose.material3.Text
import com.tencent.kuikly.compose.resources.DrawableResource
import com.tencent.kuikly.compose.resources.InternalResourceApi
import com.tencent.kuikly.compose.resources.painterResource
import com.tencent.kuikly.compose.ui.Modifier
import com.tencent.kuikly.compose.ui.draw.clip
import com.tencent.kuikly.compose.ui.graphics.Color
import com.tencent.kuikly.compose.ui.input.pointer.pointerInput
import com.tencent.kuikly.compose.ui.layout.ContentScale
import com.tencent.kuikly.compose.ui.unit.dp
import com.tencent.kuikly.compose.ui.unit.sp
import com.tencent.kuikly.core.base.attr.ImageUri
import com.tencent.kuikly.core.exception.throwRuntimeError
import com.znh.kuiklyuniversity.compose.mainPage.ListModel
import com.znh.kuiklyuniversity.compose.selfenum.AppColor

@OptIn(InternalResourceApi::class)
@Composable
fun ImageThreeTxt() {

    Column(
        modifier = Modifier.fillMaxWidth().height(150.dp).background(Color.White).clip(
            RoundedCornerShape(10.dp)
        )
    ) {
        LazyVerticalGrid(
            columns = GridCells.Fixed(3),
//            modifier = TODO(),
//            state = TODO(),
            contentPadding = PaddingValues(10.dp),
            verticalArrangement = Arrangement.spacedBy(10.dp),
            horizontalArrangement = Arrangement.spacedBy(10.dp),
            userScrollEnabled = false,// 属性加以下内容，禁止滚动
            modifier = Modifier.pointerInput(Unit) {
                awaitPointerEventScope {
                    while (true) {
                        awaitPointerEvent()
                    }
                }
            },
            content = {
                items(3) { index ->
                    Image(
                        modifier = Modifier
                            .fillMaxWidth()
                            .aspectRatio(1f)
                            .clip(RoundedCornerShape(3.dp)),
                        contentDescription = "",
                        contentScale = ContentScale.Crop,
                        painter = painterResource(
                            DrawableResource(
                                ImageUri.commonAssets(ListModel.dataBgList.get(index))
                                    .toUrl("zzzz")
                            )
                        )
                    )
                }


            }
        )
        Text(
            text = "文件说明内容", fontSize = 14.sp,
            color = AppColor.TxtCom.color, modifier = Modifier.padding(start = 10.dp)
        )
    }
}


@OptIn(InternalResourceApi::class)
@Composable
fun ImageFourTxt() {

    Row(
        modifier = Modifier.fillMaxWidth().height(150.dp).background(Color.White).clip(
            RoundedCornerShape(10.dp)
        )
    ) {
        LazyVerticalGrid(
            columns = GridCells.Fixed(2),
//            modifier = TODO(),
//            state = TODO(),
            contentPadding = PaddingValues(10.dp),
            verticalArrangement = Arrangement.spacedBy(10.dp),
            horizontalArrangement = Arrangement.spacedBy(10.dp),
            userScrollEnabled = false,// 属性加以下内容，禁止滚动
            modifier = Modifier
                .fillMaxHeight()
                .aspectRatio(1f)
                .pointerInput(Unit) {
                    awaitPointerEventScope {
                        while (true) {
                            awaitPointerEvent()
                        }
                    }
                },
            content = {
                items(4) { index ->
                    Image(
                        modifier = Modifier
                            .fillMaxWidth()
                            .aspectRatio(1f)
                            .clip(RoundedCornerShape(3.dp)),
                        contentDescription = "",
                        contentScale = ContentScale.Crop,
                        painter = painterResource(
                            DrawableResource(
                                ImageUri.commonAssets(ListModel.dataBgList.get(index))
                                    .toUrl("zzzz")
                            )
                        )
                    )
                }


            }
        )
        Text(
            text = "文件说明内容", fontSize = 14.sp,
            color = AppColor.TxtCom.color, modifier = Modifier.padding(top = 10.dp)
        )
    }

}

@OptIn(InternalResourceApi::class)
@Composable
fun ImageOneTxt() {

    Row(
        modifier = Modifier.fillMaxWidth().height(150.dp).background(Color.White).clip(
            RoundedCornerShape(10.dp)
        )
    ) {
        Image(
            modifier = Modifier
                .fillMaxHeight()
                .padding(10.dp)
                .aspectRatio(1f)
                .clip(RoundedCornerShape(3.dp)),
            contentDescription = "",
            contentScale = ContentScale.Crop,
            painter = painterResource(
                DrawableResource(
                    ImageUri.commonAssets(ListModel.dataBgList.get(9))
                        .toUrl("zzzz")
                )
            )
        )
        Text(
            text = "文件说明内容", fontSize = 14.sp,
            color = AppColor.TxtCom.color, modifier = Modifier.padding(top = 10.dp)
        )
    }
}